[
    {
        "id": "03f230443c464b5e",
        "type": "tab",
        "label": "Control Lamp",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "956f9a128667a6f0",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "With messenger app, a user controls a Lamp via a form published on a channel by this flow",
        "info": "",
        "x": 390,
        "y": 60,
        "wires": []
    },
    {
        "id": "3f090137152dcd32",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Setup a form and its components",
        "info": "",
        "x": 210,
        "y": 140,
        "wires": []
    },
    {
        "id": "e7a8a880c6b45291",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Catch submission values of the form",
        "info": "",
        "x": 200,
        "y": 360,
        "wires": []
    },
    {
        "id": "90fc77df92c915ec",
        "type": "inject",
        "z": "03f230443c464b5e",
        "name": "START",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "b0457e1234daea35"
            ]
        ]
    },
    {
        "id": "b0457e1234daea35",
        "type": "smeFormSetup",
        "z": "03f230443c464b5e",
        "connector": "",
        "name": "",
        "saveLocation": "#:(file)::savedForm",
        "saveLocationType": "flow",
        "submitEnabled": "0",
        "retainStatus": "1",
        "submitText": "Submit",
        "submitTextType": "str",
        "recipientId": "",
        "recipientIdType": "str",
        "groupChatId": "",
        "groupChatIdType": "str",
        "channelId": "",
        "channelIdType": "str",
        "receiverType": "none",
        "refName": "myLampForm",
        "refNameType": "str",
        "x": 390,
        "y": 180,
        "wires": [
            [
                "e7ceccba1f668321"
            ]
        ]
    },
    {
        "id": "e7ceccba1f668321",
        "type": "smeFormComponent",
        "z": "03f230443c464b5e",
        "name": "",
        "reference": "lampLabel",
        "referenceType": "str",
        "component": "label",
        "title": "Lamp Control Panel",
        "titleType": "str",
        "required": "false",
        "requiredType": "bool",
        "text": "",
        "textType": "str",
        "verticalList": "true",
        "verticalListType": "bool",
        "buttons": [],
        "choices": [],
        "switchValue": "false",
        "switchValueType": "bool",
        "sliderMin": 0,
        "sliderMinType": "num",
        "sliderMax": 10,
        "sliderMaxType": "num",
        "sliderStep": 0,
        "sliderStepType": "num",
        "sliderValue": 0,
        "sliderValueType": "num",
        "actionButtonTitle": "Select",
        "actionButtonTitleType": "str",
        "multiSelection": "false",
        "multiSelectionType": "bool",
        "bucketFilter": "all",
        "x": 440,
        "y": 220,
        "wires": [
            [
                "5c67027a550b710a"
            ]
        ]
    },
    {
        "id": "5c67027a550b710a",
        "type": "smeFormComponent",
        "z": "03f230443c464b5e",
        "name": "",
        "reference": "lampSwitch",
        "referenceType": "str",
        "component": "switch",
        "title": "On/Off",
        "titleType": "str",
        "required": "false",
        "requiredType": "bool",
        "text": "",
        "textType": "str",
        "verticalList": "true",
        "verticalListType": "bool",
        "buttons": [],
        "choices": [],
        "switchValue": "false",
        "switchValueType": "bool",
        "sliderMin": 0,
        "sliderMinType": "num",
        "sliderMax": 10,
        "sliderMaxType": "num",
        "sliderStep": 0,
        "sliderStepType": "num",
        "sliderValue": 0,
        "sliderValueType": "num",
        "actionButtonTitle": "Select",
        "actionButtonTitleType": "str",
        "multiSelection": "false",
        "multiSelectionType": "bool",
        "bucketFilter": "all",
        "x": 430,
        "y": 260,
        "wires": [
            [
                "dbaf74245d994ed9"
            ]
        ]
    },
    {
        "id": "dbaf74245d994ed9",
        "type": "smeFormComponent",
        "z": "03f230443c464b5e",
        "name": "",
        "reference": "lampDimmer",
        "referenceType": "str",
        "component": "slider",
        "title": "Brightness",
        "titleType": "str",
        "required": "false",
        "requiredType": "bool",
        "text": "",
        "textType": "str",
        "verticalList": "true",
        "verticalListType": "bool",
        "buttons": [],
        "choices": [],
        "switchValue": "false",
        "switchValueType": "bool",
        "sliderMin": 0,
        "sliderMinType": "num",
        "sliderMax": 10,
        "sliderMaxType": "num",
        "sliderStep": "1",
        "sliderStepType": "num",
        "sliderValue": 0,
        "sliderValueType": "num",
        "actionButtonTitle": "Select",
        "actionButtonTitleType": "str",
        "multiSelection": "false",
        "multiSelectionType": "bool",
        "bucketFilter": "all",
        "x": 430,
        "y": 300,
        "wires": [
            [
                "c09de169b9f32be1"
            ]
        ]
    },
    {
        "id": "f2e6da331084d27b",
        "type": "smeSender",
        "z": "03f230443c464b5e",
        "connector": "",
        "async": "0",
        "name": "",
        "actionName": "channel_create",
        "actionText": "Channel - Create",
        "recipientId": "",
        "recipientIdType": "str",
        "messageId": "",
        "messageIdType": "str",
        "limit": 0,
        "limitType": "num",
        "recipientIds": "",
        "recipientIdsType": "str",
        "groupChatId": "",
        "groupChatIdType": "str",
        "channelId": "",
        "channelIdType": "str",
        "title": "lampChannel",
        "titleType": "str",
        "saveLocation": "#:(file)::savedChannelId",
        "saveLocationType": "flow",
        "saveRequestIdLocation": "savedRequestId",
        "saveRequestIdLocationType": "msg",
        "logToConsole": false,
        "x": 950,
        "y": 180,
        "wires": [
            [
                "7989acea16e68a4f"
            ]
        ]
    },
    {
        "id": "c09de169b9f32be1",
        "type": "switch",
        "z": "03f230443c464b5e",
        "name": "First run?",
        "property": "#:(file)::savedChannelId",
        "propertyType": "flow",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 700,
        "y": 180,
        "wires": [
            [
                "f2e6da331084d27b"
            ],
            [
                "7989acea16e68a4f"
            ]
        ]
    },
    {
        "id": "7989acea16e68a4f",
        "type": "smeMessage",
        "z": "03f230443c464b5e",
        "name": "",
        "message": "form",
        "text": "This is a text message.",
        "textType": "str",
        "html": "<b>This is an html message</b>",
        "htmlType": "str",
        "fileIds": "",
        "fileIdsType": "str",
        "contactIds": "",
        "contactIdsType": "str",
        "locationName": "myLocation",
        "locationNameType": "str",
        "latitude": "",
        "latitudeType": "str",
        "longitude": "",
        "longitudeType": "str",
        "url": "",
        "urlType": "str",
        "enableFullScreenView": "1",
        "viewSize": "1:2",
        "channelId": "",
        "channelIdType": "str",
        "tunnelId": "",
        "tunnelIdType": "str",
        "formLocation": "#:(file)::savedForm",
        "formLocationType": "flow",
        "x": 710,
        "y": 280,
        "wires": [
            [
                "be5c0dec26e0218c"
            ]
        ]
    },
    {
        "id": "be5c0dec26e0218c",
        "type": "smeSender",
        "z": "03f230443c464b5e",
        "connector": "",
        "async": "0",
        "name": "",
        "actionName": "channel_message_send",
        "actionText": "Channel - Send Message",
        "recipientId": "",
        "recipientIdType": "str",
        "messageId": "",
        "messageIdType": "str",
        "limit": 0,
        "limitType": "num",
        "recipientIds": "",
        "recipientIdsType": "str",
        "groupChatId": "",
        "groupChatIdType": "str",
        "channelId": "#:(file)::savedChannelId",
        "channelIdType": "flow",
        "title": "",
        "titleType": "str",
        "saveLocation": "#:(file)::savedMessageId",
        "saveLocationType": "flow",
        "saveRequestIdLocation": "savedRequestId",
        "saveRequestIdLocationType": "msg",
        "logToConsole": false,
        "x": 910,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "6b2b5babc8813314",
        "type": "function",
        "z": "03f230443c464b5e",
        "name": "Lamp HW Simulator",
        "func": "if (msg.payload.on === true) {\n    node.status({fill:\"green\",shape:\"dot\",text:`on - brightness: ${msg.payload.brightness}`});\n} else if (msg.payload.on === false) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"off\"});\n}\n\nmsg = {\n    payload: {\n        on: msg.payload.on,\n        brightness: msg.payload.brightness\n    }\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\nnode.status({ fill: \"grey\", shape: \"dot\", text: \"unknown\" });",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 520,
        "wires": [
            [
                "bed0529f732b3dad"
            ]
        ]
    },
    {
        "id": "8ae9ea17937ebc91",
        "type": "change",
        "z": "03f230443c464b5e",
        "name": "Set values to payload",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "payload.on",
                "pt": "msg",
                "to": "lampSwitch",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload.brightness",
                "pt": "msg",
                "to": "lampDimmer",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 160,
        "y": 520,
        "wires": [
            [
                "6b2b5babc8813314"
            ]
        ]
    },
    {
        "id": "bed0529f732b3dad",
        "type": "smeFormUpdater",
        "z": "03f230443c464b5e",
        "name": "Update Lamp Switch",
        "location": "#:(file)::savedForm",
        "locationType": "flow",
        "compRefName": "lampSwitch",
        "compRefNameType": "str",
        "compValue": "payload.on",
        "compValueType": "msg",
        "x": 660,
        "y": 520,
        "wires": [
            [
                "fc0d1374928ff214"
            ]
        ]
    },
    {
        "id": "fc0d1374928ff214",
        "type": "smeFormUpdater",
        "z": "03f230443c464b5e",
        "name": "Update Lamp Dimmer",
        "location": "#:(file)::savedForm",
        "locationType": "flow",
        "compRefName": "lampDimmer",
        "compRefNameType": "str",
        "compValue": "payload.brightness",
        "compValueType": "msg",
        "x": 660,
        "y": 560,
        "wires": [
            [
                "528c6ddbf42a3395"
            ]
        ]
    },
    {
        "id": "afdc102d04f52a44",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Create/Reuse a channel and send the form",
        "info": "",
        "x": 800,
        "y": 140,
        "wires": []
    },
    {
        "id": "97706d3dcf3e9fda",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Send values to the lamp",
        "info": "",
        "x": 260,
        "y": 480,
        "wires": []
    },
    {
        "id": "4f00f533490c63f7",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Update the online form to get statefulness",
        "info": "",
        "x": 660,
        "y": 600,
        "wires": []
    },
    {
        "id": "5493b5d456e400ff",
        "type": "inject",
        "z": "03f230443c464b5e",
        "name": "Manual Lamp ON",
        "props": [
            {
                "p": "payload.on",
                "v": "true",
                "vt": "bool"
            },
            {
                "p": "payload.brightness",
                "v": "5",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 140,
        "y": 620,
        "wires": [
            [
                "6b2b5babc8813314"
            ]
        ]
    },
    {
        "id": "d1f9db30710ef961",
        "type": "inject",
        "z": "03f230443c464b5e",
        "name": "Manual Lamp OFF",
        "props": [
            {
                "p": "payload.on",
                "v": "false",
                "vt": "bool"
            },
            {
                "p": "payload.brightness",
                "v": "0",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 660,
        "wires": [
            [
                "6b2b5babc8813314"
            ]
        ]
    },
    {
        "id": "ffcfc919413e0f08",
        "type": "comment",
        "z": "03f230443c464b5e",
        "name": "Simulate external control of the lamp",
        "info": "",
        "x": 140,
        "y": 700,
        "wires": []
    },
    {
        "id": "528c6ddbf42a3395",
        "type": "smeMessage",
        "z": "03f230443c464b5e",
        "name": "",
        "message": "form",
        "text": "This is a text message.",
        "textType": "str",
        "html": "<b>This is an html message</b>",
        "htmlType": "str",
        "fileIds": "",
        "fileIdsType": "str",
        "contactIds": "",
        "contactIdsType": "str",
        "locationName": "myLocation",
        "locationNameType": "str",
        "latitude": "",
        "latitudeType": "str",
        "longitude": "",
        "longitudeType": "str",
        "url": "",
        "urlType": "str",
        "enableFullScreenView": "1",
        "viewSize": "1:2",
        "channelId": "",
        "channelIdType": "str",
        "tunnelId": "",
        "tunnelIdType": "str",
        "formLocation": "#:(file)::savedForm",
        "formLocationType": "flow",
        "x": 870,
        "y": 560,
        "wires": [
            [
                "cb4e117529aeb0be"
            ]
        ]
    },
    {
        "id": "cb4e117529aeb0be",
        "type": "smeSender",
        "z": "03f230443c464b5e",
        "connector": "",
        "async": "0",
        "name": "",
        "actionName": "channel_message_update",
        "actionText": "Channel - Update Message",
        "recipientId": "",
        "recipientIdType": "str",
        "messageId": "#:(file)::savedMessageId",
        "messageIdType": "flow",
        "limit": 0,
        "limitType": "num",
        "recipientIds": "",
        "recipientIdsType": "str",
        "groupChatId": "",
        "groupChatIdType": "str",
        "channelId": "#:(file)::savedChannelId",
        "channelIdType": "flow",
        "title": "",
        "titleType": "str",
        "saveLocation": "#:(file)::savedMessageId",
        "saveLocationType": "flow",
        "saveRequestIdLocation": "savedRequestId",
        "saveRequestIdLocationType": "msg",
        "logToConsole": false,
        "x": 1060,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "13a515ff602a4e29",
        "type": "smeListener",
        "z": "03f230443c464b5e",
        "connector": "",
        "x": 150,
        "y": 420,
        "wires": [
            [
                "f9182d6dea0f8988"
            ]
        ]
    },
    {
        "id": "f9182d6dea0f8988",
        "type": "smeFilter",
        "z": "03f230443c464b5e",
        "connector": "",
        "name": "",
        "filter": "submission",
        "reference": "myLampForm",
        "referenceType": "str",
        "messageId": "#:(file)::savedMessageId",
        "messageIdType": "flow",
        "extractValues": true,
        "chat": "p2p",
        "senderId": "",
        "senderIdType": "str",
        "groupChatId": "",
        "groupChatIdType": "str",
        "channelId": "",
        "channelIdType": "str",
        "requestId": "",
        "requestIdType": "str",
        "saveLocation": "savedSubmission",
        "saveLocationType": "msg",
        "x": 420,
        "y": 420,
        "wires": [
            [
                "8ae9ea17937ebc91"
            ]
        ]
    }
]